package cn.jtfadmin.base.lang.common.domain.entity;

import java.util.Objects;

/**
 * 内置实体是否允许删除
 * @author jtf
 * @since 0.0.1
 * @see BuildInAbleEntity
 * @see BuildInAbleEntityListener
 */
public class BuildInEntityDelValidUtils {
    public static ThreadLocal<Boolean> initingThreadLocal = new ThreadLocal<>();

    /**
     * 判断是会否允许删除内置实体
     *
     * @return 允许true, 禁止false
     * @see BuildInAbleEntityListener
     */
    public static boolean isAllowDel() {
        Boolean initing = initingThreadLocal.get();
        return Objects.equals(initing, Boolean.TRUE);
    }

    /**
     * 设置允许删除内置实体
     */
    public static void allowDel() {
        initingThreadLocal.set(true);
    }

    /**
     * 设置不允许删除内置实体
     */
    public static void forbidDel() {
        initingThreadLocal.remove();
    }


}
